<?php
/**
 * Created by PhpStorm.
 * User: LiuZongqi
 * Date: 2021/1/5
 * Time: 11:40
 */

namespace app\admin\validate;


use think\Validate;

class User extends Validate {
	protected $regex = [
		'username' => '^[a-zA-Z0-9]{6,25}$',
		'password' => '^[a-zA-Z0-9]{6,20}$'
	];

    protected $rule = [
        'name|姓名' => 'require',
		'username|用户名' => 'require|unique:user|regex:username',
		'password|密码' => 'require|regex:password',
		'repassword|确认密码' => 'require|confirm:password',
//        'dept|部门' => 'require',
//        'position|职位' => 'require',
//        'phone|手机' => 'require|mobile',
//        'email|邮箱' => 'require|email',
    ];

    //框架默认的 require 的错误信息为： field + 不能为空，若提示信息想要是 XX不能为空，则无需单独定义错误信息
    protected $message = [
		'username.unique' => '用户名已存在',
		'username.regex' => '用户名长度为6-25位字符，由英文字母和数字组成',
		'password.regex' => '密码长度为6-20位字符，由英文字母和数字组成',
		'repassword.confirm' => '两次密码不一致',
//		'dept.require' => '请选择部门',
//		'position.require' => '请选择职位',
	];

    protected $scene = [
        'add' => ['name','username','password','repassword'],
        'personal' => ['phone','email'],
		'import' => ['name','username','password']
    ];
}